package doublepointer;

import org.omg.CORBA.MARSHAL;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * @Author: sfy
 * @Date: 2024/1/29 21:33
 * @Description: 最长连续不重复子序列
 */
public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static int[] s = new int[100010];
    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        String[] split = br.readLine().split(" ");
        for (int i = 0; i <n; i++) {
            arr[i] = Integer.parseInt(split[i]);
        }
        int res = 0;
        for(int i=0,j=0;i<n;i++){
            s[arr[i]]++;//i指针往前走
            while(s[arr[i]]>1){//大于1说明出现了重复元素
                s[arr[j]]--;//一直剔除重复元素
                j++;//j往前移动
            }
            res = Math.max(res,i-j+1);//记录每一次位置
        }
        System.out.println(res);
    }
}
